Vue.prototype.$http= axios;
axios.defaults.baseURL="http://localhost:8080"

//======================axios的前置拦截器【拦截调用后端的请求====================//
axios.interceptors.request.use(res=>{
    let token = localStorage.getItem("token");
    if(token){
        res.headers["token"] = token;
    }
    return res;
},error => {
    Promise.reject(error)
})
//======================axios的前置拦截器【拦截调用后端的请求】====================//
//======================axios的后置拦截器【处理后台登录拦截的结果】====================//
axios.interceptors.response.use(res => {
    //后端响应的是没有登录的信息
    if (false === res.data.success && "noLogin" === res.data.msg) {
        localStorage.removeItem("token");
        localStorage.removeItem("logininfo");
        localStorage.removeItem("permissions");
        localStorage.removeItem("menus");
        location.href="/login.html"
    }
    return res;
},error => {
    Promise.reject(error)
})
//======================axios的后置拦截器【处理后台登录拦截的结果】====================//
//拦截器前端

//静态资源拦截器：拦截不发送axios请求的资源
// 核心思路：如果你访问的不是login.html 也不是register.html。就要判断当前用户是否登录过
let url = location.href;//http://localhost/login.html
let path = url.substring(url.lastIndexOf("/"));
if(path != "/login.html" && path != "/register.html" &&
    url.indexOf("/callback.html") == -1 && url.indexOf("/binder.html") == -1){
    let logininfo = localStorage.getItem("logininfo");
    if(!logininfo){
        location.href="/login.html";
    }
}

     function parseUrlParams2Obj(url){
         var obj={};
         //截取后面的数据=参数们
         let params = url.substring(url.indexOf("?")+1);

         //将参数分割
         let paramsArr = params.split("&");

         for(var i=0;i<paramsArr.length;i++){
             let param = paramsArr[i];
             let paramArr = param.split("=");

               obj[paramArr[0]] =paramArr[1];

         }
         return obj

     }